home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / MArray2.h < prev    next >
C/C++ Source or Header  |  1996-10-12  |  4KB  |  123 lines

  1. // Template array classes with like-type math ops
  2. /*
  3.  
  4. Copyright (C) 1996 John W. Eaton
  5.  
  6. This file is part of Octave.
  7.  
  8. Octave is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 2, or (at your option) any
  11. later version.
  12.  
  13. Octave is distributed in the hope that it will be useful, but WITHOUT
  14. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with Octave; see the file COPYING.  If not, write to the Free
  20. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22. */
  23.  
  24. #if defined (__GNUG__)
  25. #pragma interface
  26. #endif
  27.  
  28. #if !defined (octave_MArray2_h)
  29. #define octave_MArray2_h 1
  30.  
  31. #include "Array2.h"
  32.  
  33. // Two dimensional array with math ops.
  34.  
  35. template <class T>
  36. class MArray2 : public Array2<T>
  37. {
  38. protected:
  39.  
  40.   MArray2 (T *d, int n, int m) : Array2<T> (d, n, m) { }
  41.  
  42. public:
  43.  
  44.   MArray2 (void) : Array2<T> () { }
  45.   MArray2 (int n, int m) : Array2<T> (n, m) { }
  46.   MArray2 (int n, int m, const T& val) : Array2<T> (n, m, val) { }
  47.   MArray2 (const Array2<T>& a) : Array2<T> (a) { }
  48.   MArray2 (const MArray2<T>& a) : Array2<T> (a) { }
  49.  
  50.   ~MArray2 (void) { }
  51.  
  52.   MArray2<T>& operator = (const MArray2<T>& a)
  53.     {
  54.       Array2<T>::operator = (a);
  55.       return *this;
  56.     }
  57.  
  58.   // element by element MArray2 by scalar ops
  59.  
  60.   friend MArray2<T>& operator += (MArray2<T>& a, const T& s);
  61.   friend MArray2<T>& operator -= (MArray2<T>& a, const T& s);
  62.  
  63.   // element by element MArray2 by MArray2 ops
  64.  
  65.   friend MArray2<T>& operator += (MArray2<T>& a, const MArray2<T>& b);
  66.   friend MArray2<T>& operator -= (MArray2<T>& a, const MArray2<T>& b);
  67.  
  68.   // element by element MArray2 by scalar ops
  69.  
  70.   friend MArray2<T> operator + (const MArray2<T>& a, const T& s);
  71.   friend MArray2<T> operator - (const MArray2<T>& a, const T& s);
  72.   friend MArray2<T> operator * (const MArray2<T>& a, const T& s);
  73.   friend MArray2<T> operator / (const MArray2<T>& a, const T& s);
  74.  
  75.   // element by element scalar by MArray2 ops
  76.  
  77.   friend MArray2<T> operator + (const T& s, const MArray2<T>& a);
  78.   friend MArray2<T> operator - (const T& s, const MArray2<T>& a);
  79.   friend MArray2<T> operator * (const T& s, const MArray2<T>& a);
  80.   friend MArray2<T> operator / (const T& s, const MArray2<T>& a);
  81.  
  82.   // element by element MArray2 by MArray2 ops
  83.  
  84.   friend MArray2<T> operator + (const MArray2<T>& a, const MArray2<T>& b);
  85.   friend MArray2<T> operator - (const MArray2<T>& a, const MArray2<T>& b);
  86.  
  87.   friend MArray2<T> product (const MArray2<T>& a, const MArray2<T>& b);
  88.   friend MArray2<T> quotient (const MArray2<T>& a, const MArray2<T>& b);
  89.  
  90.   friend MArray2<T> operator - (const MArray2<T>& a);
  91. };
  92.  
  93. extern void
  94. gripe_nonconformant (const char *op, int op1_nr, int op1_nc,
  95.              int op2_nr, int op2_nc);
  96.  
  97. #define INSTANTIATE_MARRAY2_FRIENDS(T) \
  98.   template MArray2<T>& operator += (MArray2<T>& a, const T& s); \
  99.   template MArray2<T>& operator -= (MArray2<T>& a, const T& s); \
  100.   template MArray2<T>& operator += (MArray2<T>& a, const MArray2<T>& b); \
  101.   template MArray2<T>& operator -= (MArray2<T>& a, const MArray2<T>& b); \
  102.   template MArray2<T> operator + (const MArray2<T>& a, const T& s); \
  103.   template MArray2<T> operator - (const MArray2<T>& a, const T& s); \
  104.   template MArray2<T> operator * (const MArray2<T>& a, const T& s); \
  105.   template MArray2<T> operator / (const MArray2<T>& a, const T& s); \
  106.   template MArray2<T> operator + (const T& s, const MArray2<T>& a); \
  107.   template MArray2<T> operator - (const T& s, const MArray2<T>& a); \
  108.   template MArray2<T> operator * (const T& s, const MArray2<T>& a); \
  109.   template MArray2<T> operator / (const T& s, const MArray2<T>& a); \
  110.   template MArray2<T> operator + (const MArray2<T>& a, const MArray2<T>& b); \
  111.   template MArray2<T> operator - (const MArray2<T>& a, const MArray2<T>& b); \
  112.   template MArray2<T> product (const MArray2<T>& a, const MArray2<T>& b); \
  113.   template MArray2<T> quotient (const MArray2<T>& a, const MArray2<T>& b); \
  114.   template MArray2<T> operator - (const MArray2<T>& a);
  115.  
  116. #endif
  117.  
  118. /*
  119. ;;; Local Variables: ***
  120. ;;; mode: C++ ***
  121. ;;; End: ***
  122. */
  123.